<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 博主接口
 */
class Blogger extends Api
{
    protected $noNeedRight = ['*'];


    //博主列表
    public function page()
    {
        $province = input('province','');

        $city = input('city','');

        $area = input('area','');

        $is_recommend = input('is_recommend',0);

        $where = [];

        if ($province){
            $where['b.province'] = $province;
        }

        if ($city){
            $where['b.city'] = $city;
        }

        if ($area){
            $where['b.area'] = $area;
        }

        if ($is_recommend){
            $where['b.is_recommend'] = 1;
        }

        $list = \app\admin\model\blogger\Blogger::alias('b')
            ->join('user u', 'u.id=b.user_id', 'LEFT')
            ->field('b.*,u.nickname,u.avatar')
            ->where($where)
            ->order('b.createtime desc')
            ->paginate(10, false, ['query' => request()->get()]);

        $this->success('请求成功',$list);
    }

    //博主详情
    public function info()
    {
        $id = input('id',0);

        $info = \app\admin\model\blogger\Blogger::get($id);

        $this->success('请求成功',$info);
    }
}